/**
 * basicOverview.js
 * 数字化教学概览action, 描述概览页面中的用户行为
 *
 * created by qiuwei
 * version 1.0.0
 * 2016年03月09日
 */

import { create } from './asyncActionCreator';
import { SUBJECT_URL,
		 GRADE_URL, 
		 COUNTY_URL, 
		 SCHOOL_URL,
		 BASIC_DATA_DETAIL_URL,
		 BASIC_DATA_CHART_URL,
		 BASIC_DATA_LIST_URL,
		 ACTIVE_DATA_LIST_URL,
		 ACTIVE_DATA_CHART_URL,
		 ACTIVE_DATA_DETAIL_URL
} from '../../../constants/API'

/**
 * 在`基础概况`和`活跃热力图`之间切换
 * @type {String}
 */
export const SWITCH_VIEW = 'switch view';
export const switchView = (view) => ({
	type: SWITCH_VIEW,
	payload: {
		view
	}
});


/**
 * 获取基础视图列表
 * @type {String}
 * @param {object} [endDate,dataSource] [获取截止日期和数据表]
 * @return {object} [Action描述]
 */
export const GET_BASIC_TABLE_REQUEST = 'get basic table request',
 			 GET_BASIC_TABLE_SUCCESS = 'get basic table success',
  			 GET_BASIC_TABLE_FAILURE = 'get basic table failure';
export const getBasicTableRequest = () => ({
	type:GET_BASIC_TABLE_REQUEST,
	payload:{}
});
export const getBasicTableSuccess = (dataSource) => ({
	type:GET_BASIC_TABLE_SUCCESS,
	payload:{
		dataSource
	}
});
export const getBasicTableFailure = (errorMessage) => ({
	type:GET_BASIC_TABLE_FAILURE,
	payload:{
		errorMessage
	}
});
export const getBasicTable = (area, params) => {
	return create(`${BASIC_DATA_LIST_URL}/${area}`,
		getBasicTableRequest,
		getBasicTableSuccess,
		getBasicTableFailure,
		params)
};
/**
 * 获取师生活跃概况表
 * @type {String}
 * @param {object} [dataSource] [获取数据表]
 * @return {object} Action描述
 */
export const GET_ACTIVE_TABLE_REQUEST = 'get active table request',
			 GET_ACTIVE_TABLE_SUCCESS = 'get active table success',
			 GET_ACTIVE_TABLE_FAILURE = 'get active table failure';
export const getActiveTableRequest = () => ({
	type:GET_ACTIVE_TABLE_REQUEST,
	payload:{}
});
export const getActiveTableSuccess = (dataSource) => ({
	type:GET_ACTIVE_TABLE_SUCCESS,
	payload: {
		dataSource
	}
});
export const getActiveTableFailure = (errorMessage) => ({
	type:GET_ACTIVE_TABLE_FAILURE,
	payload:{
		errorMessage
	}
});
export const getActiveTable = (area,params) => {
	return create(`${ACTIVE_DATA_LIST_URL}/${area}`,
		getActiveTableRequest,
		getActiveTableSuccess,
		getActiveTableFailure,
		params)
};

/**
 * 获取学生累计、教师累计、学校累计增长视图
 * @param  {object} dataSource   [三级数组，包含学生，教师，学校累计视图数据]
 * @return {object}        [description]
 */
export const GET_CHARTS_BASIC_REQUEST = 'get charts basic request',
			 GET_CHARTS_BASIC_SUCCESS = 'get charts basic success',
			 GET_CHARTS_BASIC_FAILURE = 'get charts basic failure';
export const getChartsBasicRequest = () => ({
	type: GET_CHARTS_BASIC_REQUEST,
	payload: {}
});

export const getChartsBasicSuccess = (dataSource) => ({
	type: GET_CHARTS_BASIC_SUCCESS,
	payload: {
		dataSource
	}
});

export const getChartsBasicFailure = (errorMessage) => ({
	type: GET_CHARTS_BASIC_FAILURE,
	payload: {
		errorMessage
	}
});

export const getChartsBasic = (area,params) => {
	return create(`${BASIC_DATA_CHART_URL}/${area}`, 
		getChartsBasicRequest,
		getChartsBasicSuccess,
		getChartsBasicFailure,
		params);
};

/**
 * 切换学生、老师、学校累计增长视图
 * @param  {object} line   [description]
 * @param  {object} column [description]
 * @return {object}        [description]
 */
export const SWITCH_CHARTS_BASIC = 'switch charts basic';

export const switchChartsBasic = (pointer) => ({
	type:SWITCH_CHARTS_BASIC,
	payload:{
		pointer
	}
});

/**
 * [获取活跃热力图数据]
 * @type {String}
 * @param {object} geo [description]
 * @return {object} [description]
 */
export const GET_CHARTS_ACTIVE_REQUEST = 'get charts active request',
			 GET_CHARTS_ACTIVE_SUCCESS = 'get charts active success',
			 GET_CHARTS_ACTIVE_FAILURE = 'get charts active failure';
export const getChartsActiveRequest = () => ({
	type:GET_CHARTS_ACTIVE_REQUEST,
	payload:{}
});
export const getChartsActiveSuccess = (geo) => ({
	type:GET_CHARTS_ACTIVE_SUCCESS,
	payload:{
		geo
	}
});
export const getChartsActiveFailure = (errorMessage) => ({
	type:GET_CHARTS_ACTIVE_FAILURE,
	payload:{
		errorMessage
	}
});
export const getChartsActive = (area, params) => {
	return create(`${ACTIVE_DATA_CHART_URL}/${area}`,
		getChartsActiveRequest,
		getChartsActiveSuccess,
		getChartsActiveFailure,
		params)
};
/**
 * 异步获取数据详情
 * @type {String}
 * @param {object} dataSource [description]
 * @return {object} 
 */
export const GET_BASIC_DETAIL_REQUEST = 'get basic detail request',
			 GET_BASIC_DETAIL_SUCCESS = 'get basic detail success',
			 GET_BASIC_DETAIL_FAILURE = 'get basic detail failure';
export const getBasicDetailRequest = () => ({
	type:GET_BASIC_DETAIL_REQUEST,
	payload:{}
});
export const getBasicDetailSuccess = (dataSource) => ({
	type:GET_BASIC_DETAIL_SUCCESS,
	payload:{
		dataSource
	}
});
export const getBasicDetailFailure = (errorMessage) => ({
	type:GET_BASIC_DETAIL_FAILURE,
	payload:{
		errorMessage
	}
});
export const getBasicDetail = (area,params) => {
	return create(`${BASIC_DATA_DETAIL_URL}/${area}`,
		getBasicDetailRequest,
		getBasicDetailSuccess,
		getBasicDetailFailure,
		params)
};
/**
 * [SELECT_BASIC_DETAIL_PAGEINDEX 基础视图数据详情翻页]
 * @type {String}
 */
export const SELECT_BASIC_DETAIL_PAGEINDEX = 'select basic detail pageIndex',
			 SELECT_BASIC_DETAIL_CURRENT_PAGEINDEX = 'select basic detail current pageIndex';
export const selectBasicDetailPageIndex = ( pageIndex ) => ({
	type:SELECT_BASIC_DETAIL_PAGEINDEX,
	payload:{
		pageIndex
	}
});
export const selectBasicDetailCurrentPageIndex = ( currentPageIndex ) => ({
	type:SELECT_BASIC_DETAIL_CURRENT_PAGEINDEX,
	payload:{
		currentPageIndex
	}
});
/**
 * 活页热力图数据详情
 * @type {String}
 */
export const GET_ACTIVE_DETAIL_REQUEST = 'get active detail request',
			 GET_ACTIVE_DETAIL_SUCCESS = 'get active detail success',
			 GET_ACTIVE_DETAIL_FAILURE = 'get active detail failure';
export const getActiveDetailRequest = () => ({
	type:GET_ACTIVE_DETAIL_REQUEST,
	payload:{}
});
export const getActiveDetailSuccess = (dataSource) => ({
	type:GET_ACTIVE_DETAIL_SUCCESS,
	payload:{
		dataSource
	}
});
export const getActiveDetailFailure = (errorMessage) => ({
	type:GET_ACTIVE_DETAIL_FAILURE,
	payload:{
		errorMessage
	}
});
export const getActiveDetail = (area,params) => {
	return create(`${ACTIVE_DATA_DETAIL_URL}/${area}`,
		getActiveDetailRequest,
		getActiveDetailSuccess,
		getActiveDetailFailure,
		params)
};
/**
 * 活跃热力图数据详情翻页
 */
export const SELECT_ACTIVE_DETAIL_PAGEINDEX = 'select active detail pageIndex',
			 SELECT_ACTIVE_DETAIL_CURRENT_PAGEINDEX = 'select active detail current pageIndex';
export const selectActiveDetailPageIndex = ( pageIndex ) => ({
	type:SELECT_ACTIVE_DETAIL_PAGEINDEX,
	payload:{
		pageIndex
	}
});
export const selectActiveDetailCurrentPageIndex = (currentPageIndex) => ({
	type:SELECT_ACTIVE_DETAIL_CURRENT_PAGEINDEX,
	payload:{
		currentPageIndex
	}
});
/**
 * 重置状态
 * @type {String}
 */
export const RESET = 'reset basicOverview state';
export const reset = () => ({
	type: RESET,
	payload: {}
});












